{extend name="iframe" /}

{block name="body"}
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <form action="{:request()->url()}" method="post" class="xn_ajax" data-type="open">
        <div class="layui-form-item">
            <label class="layui-form-label">所属位置</label>
            <div class="layui-input-block">
                <select name="position" lay-verify="required" lay-filter="position">
                    <option value="3" {if $data.position==3}selected{/if}>流程</option>
                    <option value="4" {if $data.position==4}selected{/if}>支持</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">值</label>
            <div class="layui-input-block" id="value">
                {if $data['position'] == 3}
                {foreach name="position2List" item="vo"}
                <input type="checkbox" name="value[]" value="{$vo['id']}" {if condition="in_array($vo['id'],$data['value'])"} checked="checked"{/if} lay-skin="primary" title="{$vo['sort']}.{$vo['title']}">
                {/foreach}
                {else}
                <input type="text" name="step" placeholder="" autocomplete="off" class="layui-input" value="{$data['step']}">
                {/if}
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" lay-submit class="layui-btn">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="js"}
<script>
    var form = layui.form;
    form.on('select(position)', function(res) { 
        $("#value").empty();
        if(res.value == 3){
            $.get("{:url('admin/DataContentChipPosition/getSonPosition')}?pid="+res.value,function(result){
                if(result.status){
                    var html = '';
                    $.each(result.data,function(index,item){
                        html += '<input type="checkbox" name="value[]" value="'+item.id+'" lay-skin="primary" title="'+item.sort+'.'+item.title+'">';
                    });
                    $("#value").html(html);
                    form.render('checkbox');
                }
            });
        }else{
            var html = '<input type="text" name="step" placeholder="" autocomplete="off" class="layui-input" value="{$data.step}">';
            $("#value").html(html);
        }
        
    })
</script>
{/block}